/**
 * Created by Administrator on 2016/10/24.
 */
angular.module('redBookAPP.service',[])
    .factory('HomeFactory',function ($resource,$rootScope) {
        var url = [
            "http://www.xiaohongshu.com/api/sns/v3/homefeed?oid=homefeed_recommend&value=simple&page=1&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477278945&sign=793a4efbafae4e3d3cbb9bc51d2d2da7",
            "",
            "http://www.xiaohongshu.com/api/sns/v3/homefeed?oid=homefeed.men&value=simple&page=1&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477310997&sign=1a0d94de02c41479c899a89d0ee675bc",
            "http://www.xiaohongshu.com/api/sns/v3/homefeed?oid=homefeed.skincare&value=simple&page=1&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477311438&sign=3f9cc19bcab2ccda6b8bf6615d43d232",
            "http://www.xiaohongshu.com/api/sns/v3/homefeed?oid=homefeed.travel&value=simple&page=1&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477311666&sign=5664d64b51afbd29b13cfc81a2f0a6be",
            "http://www.xiaohongshu.com/api/sns/v3/homefeed?oid=homefeed.life&value=simple&page=1&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477311611&sign=8b3127cc0ad2cac231b42a84c2f7ed11",
            "http://www.xiaohongshu.com/api/sns/v3/homefeed?oid=homefeed.fashion&value=simple&page=1&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477311694&sign=a9162f831f27170ad1fd3455bccf6e24",
            "http://www.xiaohongshu.com/api/sns/v3/homefeed?oid=homefeed.makeup&value=simple&page=1&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477311727&sign=fe4b9a4f9e8801df4448bb7af66f12b1",
            "http://www.xiaohongshu.com/api/sns/v3/homefeed?oid=homefeed.babycare&value=simple&page=1&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477311770&sign=f128ea4570316b6dde3e3daf66855c51"
        ];
   
        var data = {};
        return {
            //异步请求
            getHome:function (i) {
                $resource(url[i-1],{},{
                    query:{
                        method:"get",
                        timeout:20000
                    }
                }).query({},function (r) {
                    //通知controll拿数据
                    data.data = r.data;
                    $rootScope.$broadcast('updateHome');
                })
            },
            getHomeData:function () {
                return data.data
            }
        }
    })

    //详细笔记 页
    .factory('XiangpingFactory',function ($resource,$rootScope) {
        var url = [
            'http://www.xiaohongshu.com/api/sns/v5/note/58046651046fc515c7cc3a6f?platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477539754&sign=204445c9af0376f51d8d76333af99077',
            'http://www.xiaohongshu.com/api/sns/v2/note/58046651046fc515c7cc3a6f/related?page=1&tag_oid=&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477539755&sign=86be4b568c39ced65df2dd28ef13b700',
            'http://www.xiaohongshu.com/api/sns/v2/note/58118b4db46c5d19cc15f294/related?page=1&tag_oid=brand.5360a724b4c4d60a80217833&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477569498&sign=6ea2324defcd208c668389dd692d534e'
        ];
        var data = {};
        return {
            getXiangqing: function () {
                $resource(url[0],{},{
                    query:{
                        method:"get",
                        timeout:20000
                    }
                }).query({},function (r) {
                    data.data1 = r.data;
                    console.log(data.data1);
                    $rootScope.$broadcast('updateHome');
                })
            },
            getXiangqing_xia: function (bb) {
                console.log(bb);
                if(bb=='1'){
                    $resource(url[1],{},{
                        query:{
                            method:"get",
                            timeout:20000
                        }
                    }).query({},function (r) {
                        data.data2 = r.data;
                        console.log(111111);
                        $rootScope.$broadcast('updateHome_s');
                    })
                }
                else {
                    $resource(url[2],{},{
                        query:{
                            method:"get",
                            timeout:20000
                        }
                    }).query({},function (r) {
                        data.data2 = r.data;
                        console.log(2222222);
                        $rootScope.$broadcast('updateHome_s');
                    })
                }
            },
            getXiangqingData:function () {
                return data.data1
            },
            getXiangqingData_xia:function () {
                return data.data2
            }
            
        }
    })
    //全部评论
    .factory('PinglunFactory',function ($resource,$rootScope) {
        var url = 'http://www.xiaohongshu.com/api/sns/v3/note/580d9cfc40c7946eb820ab10/comment/list?platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477722214&sign=a0b10973a863752bfd9259c42208519f';
        var data = {};
        return {
            //异步请求
            getPinglun:function () {
                $resource(url,{},{
                    query:{
                        method:"get",
                        timeout:20000
                    }
                }).query({},function (r) {
                    //通知controll拿数据
                    data.data = r.data;
                    $rootScope.$broadcast('updatePinglun');
                })
            },
            getPinglunData:function () {
                return data.data
            }
        }
    })
    //发现页面的服务
    .factory('FindFactory',function ($resource,$rootScope) {
        var url = [
        			"http://www.xiaohongshu.com/api/sns/v3/explore/banner?mode=bottom_hot_boards&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477302053&sign=aeeca913658a33e1fa849c64c1a7974b",
        			"http://www.xiaohongshu.com/api/sns/v1/board/hot?page=1&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477538442&sign=c98e9fdc2caed4ecd3834941a60d364f"
        		]
        var data = {};
        var zhuanji={};
        return {
            //异步请求
            getFind:function () {
            	$resource(url[0],{},{
		            query:{
		                method:"get",
		                timeout:20000
		            }
		        }).query({},function (r) {
                    // console.log(r.data);
                    //通知controll拿数据
                    data.data = r.data;
                    $rootScope.$broadcast('updateHots');
                })
            },
            getFindData:function () {
                return data.data
            },
            getFindZhuanji:function(){
            	$resource(url[1],{},{
		            query:{
		                method:"get",
		                timeout:20000
		            }
		        }).query({},function (r) {
                    zhuanji.data = r.data;
                })
            },
             getFindZhuanjiData:function () {
                return zhuanji.data;
            }
        }
    })
    //购买页面的服务
    .factory('PurchaseFactory',function ($resource,$rootScope) {

    	var url = [
           "http://www.xiaohongshu.com/api/store/v2/banners?oid=categoryforall&is_special=0&display_long_items_title=0&display_banner_link_type=0&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477384763&sign=08149253a58d43e33bb40950441488f9",
            "http://www.xiaohongshu.com/api/store/v2/banners?oid=577e2a05805d897d07435686&is_special=0&display_long_items_title=0&display_banner_link_type=0&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477385013&sign=ae3faa81745cbb26255222e6a00b14e9",
			"http://www.xiaohongshu.com/api/store/v2/banners?oid=577e2a05805d897d0743568a&is_special=0&display_long_items_title=0&display_banner_link_type=0&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477385086&sign=0179cd25bbc32f1c9f0cd2ad3758cd3c",
			"http://www.xiaohongshu.com/api/store/v2/banners?oid=577e2a05805d897d07435685&is_special=0&display_long_items_title=0&display_banner_link_type=0&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477385133&sign=067e1a781a5aa718ed570c84d8c8ee52",
			"http://www.xiaohongshu.com/api/store/v2/banners?oid=577e2a05805d897d07435688&is_special=0&display_long_items_title=0&display_banner_link_type=0&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477385174&sign=f620b7399969fd14f12f76285ed0cfd2",
			"http://www.xiaohongshu.com/api/store/v2/banners?oid=577e2a05805d897d07435684&is_special=0&display_long_items_title=0&display_banner_link_type=0&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477385205&sign=dcb45f8b6bf62de225dd13aea2299c3c",
			"http://www.xiaohongshu.com/api/store/v2/banners?oid=577e2a05805d897d0743568b&is_special=0&display_long_items_title=0&display_banner_link_type=0&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477385243&sign=b39f03543b1e2009bb52abb13a448ec2",
			"http://www.xiaohongshu.com/api/store/v2/banners?oid=57b1776a805d897db30244d1&is_special=0&display_long_items_title=0&display_banner_link_type=0&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477385278&sign=4499221d828431e0e67a64c935f91e66",
			"http://www.xiaohongshu.com/api/store/v2/banners?oid=577e2a05805d897d0743568d&is_special=0&display_long_items_title=0&display_banner_link_type=0&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477385330&sign=ef303b95d5080e27f85b60b8d5566663",
			"http://www.xiaohongshu.com/api/store/v2/banners?oid=577e2a05805d897d0743568e&is_special=0&display_long_items_title=0&display_banner_link_type=0&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477385361&sign=8b2805bd609b6fd393efbae29ca24918",
			"http://www.xiaohongshu.com/api/store/v2/banners?oid=577e2a06805d897d0743568f&is_special=0&display_long_items_title=0&display_banner_link_type=0&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477385399&sign=b8b27135f655ecb4f43acd1a1a3210f4",
			"",
			"http://www.xiaohongshu.com/api/store/v1/categories/577e2a05805d897d07435686/items?page=1&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477538653&sign=3eb4c449fb0e348a9483e5290e531c03",
        	"http://www.xiaohongshu.com/api/store/v1/categories/577e2a05805d897d0743568a/items?page=1&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477538851&sign=37dd0e8117fd9c7da1b1141ac52d7785",
        	"http://www.xiaohongshu.com/api/store/v1/categories/577e2a05805d897d07435685/items?page=1&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477538910&sign=7d2abf0eb4fc4bc9f13275ee8fd1fe8d",
        	"http://www.xiaohongshu.com/api/store/v1/categories/577e2a05805d897d07435688/items?page=1&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477538950&sign=dda7c7a92b937bbc3d78178870e570a3",
        	"http://www.xiaohongshu.com/api/store/v1/categories/577e2a05805d897d07435684/items?page=1&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477539035&sign=997e8686c1c954b29f12ad690e5d0f67",
        	"http://www.xiaohongshu.com/api/store/v1/categories/577e2a05805d897d0743568b/items?page=1&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477539077&sign=d513f16f0ec903ba0207d14e66402c76",
        	"http://www.xiaohongshu.com/api/store/v1/categories/57b1776a805d897db30244d1/items?page=1&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477539102&sign=0747a596349e10135ab3fd8be19f94f1",
        	"http://www.xiaohongshu.com/api/store/v1/categories/577e2a05805d897d0743568d/items?page=1&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477539130&sign=8a1394a9ed207789ae257b1989f2f0bc",
        	"http://www.xiaohongshu.com/api/store/v1/categories/577e2a05805d897d0743568e/items?page=1&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477539165&sign=59135c3440cb5cc1ebd5ae4164ecfa32",
        	"http://www.xiaohongshu.com/api/store/v1/categories/577e2a06805d897d0743568f/items?page=1&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.10.100&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1477539193&sign=1f7d36a8179e28d4b91e7e8da0162b93"
        ];
       var data = {};
       var datas={};
        return {
            //异步请求
            getPurchase:function (i) {
                $resource(url[i],{},{
                    query:{
                        method:"get",
                        timeout:20000
                    }
                }).query({},function (r) {
                    data.data = r.data;
                    $rootScope.$broadcast('updatePurchase');
                })
            },
            getPurchaseData:function () {
                return data.data;
            },
            getPurchaseXia:function (i) {
                $resource(url[i+11],{},{
                    query:{
                        method:"get",
                        timeout:20000
                    }

                }).query({},function (r) {
                    datas.data = r.data;
                    $rootScope.$broadcast('updatePurchase');
                })
            },
            getPurchaseXiaData:function () {
                return datas.data
            }
        }
    })
    //消息页面服务
    .factory('NewsFactory',function ($resource,$rootScope) {
    
        var url = [
        		"http://www.xiaohongshu.com/api/sns/v2/message/activities?start=&num=10&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.11.020&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1478597723&sign=e09bbca69f320f9358c5fb9c43b85b6f",
        		"",
        		"http://www.xiaohongshu.com/api/sns/v1/message/sysmessage?num=10&platform=Android&deviceId=a52a24da-b1e7-3a2e-bfe2-e03e946cdca3&versionName=4.11.020&channel=YingYongBao&sid=session.1161766308794767709&lang=zh-CN&t=1478597746&sign=d7b39b08c64c14a3a612ce58005aef80"
            ];
   
        var news= {};
        return {
            //异步请求
            getNews:function (i) {
                $resource(url[i],{},{
                    query:{
                        method:"get",
                        timeout:20000
                    }
                }).query({},function (r) {
                    news.data = r.data;
                    $rootScope.$broadcast('updateNews');
                })
            },
            getNewsData:function () {
                return news.data
            }
        }
    })
